import Vue from 'vue'
import Vuex from 'vuex'
import muta from './mutations'
import act from './actions'
Vue.use(Vuex)

let state = {
    productlist: JSON.parse(localStorage.getItem('productlist')) || [],
}

const store = new Vuex.Store({
    // 状态值
    state: state,
    // mutations唯一的目的就是为了修改state中的状态
    mutations: muta,
    actions: act,
    // 获取state状态值里的productlist长度
    getters: {
        cartlength(state) {
            return state.productlist.length
            // 获取state状态值里的productlist列表
        }, cartlist(state) {
            return state.productlist
        }
    }
})

export default store